<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <!-- <script src="js/axios.js"></script> -->
    
</head>
<body>  
    <!-- 组件之间的通信 非父子组件通信：bus
    -->
    <div id="app">
        <com1></com1>
        <com2></com2>
    </div>
    <script>
        const bus = new Vue();
        Vue.component("com1",{
            template:`
                <div>
                    <h1>hello world</h1>
                    <button @click="sendMsg">发送数据</button>
                </div>
            `,
            methods:{
                sendMsg(){
                    bus.$emit("myevent","hello");
                }
            }
        })
        Vue.component("com2", {
            template:`
                <div>{{ getMsg }}</div>
            `,
            data(){
                return{
                    getMsg:""
                }
            },
            mounted(){
                bus.$on("myevent",data => {
                    console.log(data)
                    this.getMsg = data
                })
            }
        })
        var app = new Vue({
            el: "#app"
        });
    </script>
</body>
</html>